package com.business.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.domain.T_task_node_instance;
import com.easyworkflow.web.spring.WorkFlowController;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.business.domain.T_bussines_apply;
//import com.business.mapper.T_bussines_applyMapper;
import com.business.service.T_bussines_applyService;

@Controller
@RequestMapping("/t_bussines_apply")

public class T_bussines_applyController extends WorkFlowController{

	private static Logger log = Logger.getLogger(T_bussines_applyController.class.getName());

	@Resource
    private T_bussines_applyService t_bussines_applyService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_bussines_applyMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_bussines_apply信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_bussines_apply")
	@ResponseBody
	public Pg getAllT_bussines_apply(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_bussines_apply t_bussines_apply = new T_bussines_apply();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_bussines_apply.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("companyname")!=null&&!"".equals(request.getParameter("companyname"))){
	        	t_bussines_apply.setCompanyname(request.getParameter("companyname"));
	        }
			if(request.getParameter("linkman")!=null&&!"".equals(request.getParameter("linkman"))){
	        	t_bussines_apply.setLinkman(request.getParameter("linkman"));
	        }
			if(request.getParameter("tel")!=null&&!"".equals(request.getParameter("tel"))){
	        	t_bussines_apply.setTel(request.getParameter("tel"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_bussines_apply.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_bussines_apply.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_bussines_apply.setExt3(request.getParameter("ext3"));
	        }
			if(request.getParameter("ext4")!=null&&!"".equals(request.getParameter("ext4"))){
	        	t_bussines_apply.setExt4(request.getParameter("ext4"));
	        }
			if(request.getParameter("ext5")!=null&&!"".equals(request.getParameter("ext5"))){
	        	t_bussines_apply.setExt5(request.getParameter("ext5"));
	        }
			if(request.getParameter("ext6")!=null&&!"".equals(request.getParameter("ext6"))){
	        	t_bussines_apply.setExt6(request.getParameter("ext6"));
	        }
			if(request.getParameter("buildingname")!=null&&!"".equals(request.getParameter("buildingname"))){
	        	t_bussines_apply.setBuildingname(request.getParameter("buildingname"));
	        }
			if(request.getParameter("floorno")!=null&&!"".equals(request.getParameter("floorno"))){
	        	t_bussines_apply.setFloorno(request.getParameter("floorno"));
	        }
			if(request.getParameter("housename")!=null&&!"".equals(request.getParameter("housename"))){
	        	t_bussines_apply.setHousename(request.getParameter("housename"));
	        }
			if(request.getParameter("area")!=null&&!"".equals(request.getParameter("area"))){
	        	t_bussines_apply.setArea(request.getParameter("area"));
	        }
			if(request.getParameter("fix")!=null&&!"".equals(request.getParameter("fix"))){
	        	t_bussines_apply.setFix(request.getParameter("fix"));
	        }
			if(request.getParameter("applytype")!=null&&!"".equals(request.getParameter("applytype"))){
	        	t_bussines_apply.setApplytype(request.getParameter("applytype"));
	        }
			if(request.getParameter("channelname")!=null&&!"".equals(request.getParameter("channelname"))){
	        	t_bussines_apply.setChannelname(request.getParameter("channelname"));
	        }
			if(request.getParameter("creater")!=null&&!"".equals(request.getParameter("creater"))){
	        	t_bussines_apply.setCreater(request.getParameter("creater"));
	        }
			if(request.getParameter("creattime")!=null&&!"".equals(request.getParameter("creattime"))){
	        	t_bussines_apply.setCreattime(request.getParameter("creattime"));
	        }
			if(request.getParameter("updater")!=null&&!"".equals(request.getParameter("updater"))){
	        	t_bussines_apply.setUpdater(request.getParameter("updater"));
	        }
			if(request.getParameter("updattime")!=null&&!"".equals(request.getParameter("updattime"))){
	        	t_bussines_apply.setUpdattime(request.getParameter("updattime"));
	        }
			if(request.getParameter("applytime")!=null&&!"".equals(request.getParameter("applytime"))){
	        	t_bussines_apply.setApplytime(request.getParameter("applytime"));
	        }
			if(request.getParameter("biztype")!=null&&!"".equals(request.getParameter("biztype"))){
	        	t_bussines_apply.setBiztype(request.getParameter("biztype"));
	        }
      	    if(request.getParameter("applyid")!=null&&!"".equals(request.getParameter("applyid"))){
	        	t_bussines_apply.setApplyid(new Integer(request.getParameter("applyid")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_bussines_apply.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_bussines_apply.setEnddate(request.getParameter("enddate"));
	        }
	        t_bussines_apply.setStartNo( startIndex );
	        t_bussines_apply.setPageSize( pageSize );
	        t_bussines_apply.setEndNo( pageSize );
	    	List<T_bussines_apply> findAll = t_bussines_applyService.findAll(t_bussines_apply);
	        int totalCount = t_bussines_applyService.findCountAll(t_bussines_apply);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_bussines_applyList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_bussines_applyList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_bussines_apply信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_bussines_apply
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_bussines_apply")
	@ResponseBody
	public JsonVO saveT_bussines_apply(T_bussines_apply t_bussines_apply, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_bussines_applyService.save(t_bussines_apply)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3。1、修改T_bussines_apply信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_bussines_apply
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_bussines_apply")
	@ResponseBody
	public JsonVO updateT_bussines_apply(T_bussines_apply t_bussines_apply, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_bussines_apply t_bussines_applyTemp = t_bussines_applyService.findById(t_bussines_apply);
		//t_bussines_applyTemp.setXXX(t_bussines_apply.getXXX());
		//if(t_bussines_applyService.update(t_bussines_applyTemp)){

		if(t_bussines_applyService.update(t_bussines_apply)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

    /**
     * 3。2、提交审核业务数据
     * 修改T_bussines_apply信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_bussines_apply
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/tjshT_bussines_apply")
    @ResponseBody
    public JsonVO tjshT_company(T_bussines_apply t_bussines_apply, HttpServletRequest request) {
        //启动工作流； 请假流程；
        return startMyTask( getTaskIdByBiztype(t_bussines_apply.getBiztype()),t_bussines_apply.getBiztype(), t_bussines_apply.getApplyid(), request);
    }

    /**
     * 3.3、提交T_bussines_apply审核通过，并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shtgT_bussines_apply")
    @ResponseBody
    public JsonVO shtgT_bussines_apply(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyAgree(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }

    /**
     * 3.4、提交T_bussines_apply审核退回，信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shthT_bussines_apply")
    @ResponseBody
    public JsonVO shthT_bussines_apply(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyBack(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }
    
	/**
	 * 4、根据id查询T_bussines_apply单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_bussines_apply json格式字符串
	 */
	@RequestMapping("/getT_bussines_apply")
	@ResponseBody
	public T_bussines_apply getT_bussines_apply(Integer id,HttpServletRequest request){
		T_bussines_apply t_bussines_apply = new T_bussines_apply();
		t_bussines_apply.setApplyid(id);
		return t_bussines_applyService.findById(t_bussines_apply);
	}

	/**
	 * 5、删除T_bussines_apply根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_bussines_apply")
	@ResponseBody
	public JsonVO delT_bussines_apply(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_bussines_apply t_bussines_apply = new T_bussines_apply();
		t_bussines_apply.setApplyid(id);

		if(t_bussines_applyService.delete(t_bussines_apply)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_bussines_apply/toT_bussines_applyList查询所有数据页面
	 *  return /WEB-INF/views/business/t_bussines_apply/t_bussines_applyList.jsp
	 */
    @RequestMapping(value = "/toT_bussines_applyList")
    public String toT_bussines_applyList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_bussines_apply/t_bussines_applyList.jsp------");
        return "business/t_bussines_apply/t_bussines_applyList";
    }

	/**
	 * 7、新增、修改、详情页面t_bussines_apply/toT_bussines_applyCurd跳转
     * business/t_bussines_apply/T_bussines_applyCurd.jsp
	 */
    @RequestMapping(value = "/toT_bussines_applyCurd")
    public String toT_bussines_applyCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_bussines_apply/t_bussines_applyCurd.jsp------");
        return "business/t_bussines_apply/t_bussines_applyCurd";
    }

    /**
	 * 8、批量删除T_bussines_apply根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_bussines_applyBatch")
	public String delT_bussines_applyBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_bussines_apply t_bussines_apply = new T_bussines_apply();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_bussines_apply.setApplyid(new Integer(ids[i]).intValue());
			t_bussines_applyService.delete(t_bussines_apply);
		}
		if(j==ids.length){
			log.debug("------t_bussines_apply批量删除成功！------");
		}else{
			log.error("------t_bussines_apply批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_bussines_apply/getAllT_bussines_apply";
	}
*/



}









